package dialer.ws.business.service.impl;

import java.io.Serializable;

import org.aspectj.weaver.ast.Call;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dialer.ws.base.exception.EntityException;
import dialer.ws.base.query.NamedQueryParameter;
import dialer.ws.base.service.impl.GenericServiceImpl;
import dialer.ws.business.dao.CallDAO;
import dialer.ws.business.service.CallService;

@Service("callService")
public class CallServiceImpl extends GenericServiceImpl<Call, Integer> implements CallService, Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4664659487259925418L;

	private CallDAO callDAO;

	@Autowired
	public CallServiceImpl(CallDAO callDAO) {
		super(callDAO);
		this.callDAO = callDAO;
	}

	@Override
	public Integer getProcesValidFinish(Integer id_campaign, Integer retries) {
		Long result = null;
		NamedQueryParameter param1 = new NamedQueryParameter("id_campaign", id_campaign);
		NamedQueryParameter param2 = new NamedQueryParameter("retries", retries);
		try {
			result = (Long) callDAO.findByNamedQueryNamedParameterReturnObject("Call.getProcesValidFinish", param1,
					param2);
		} catch (EntityException e) {
			e.printStackTrace();
		}
		return result == null ? 0 : result.intValue();
	}

	public Integer getProcesInvValidFinish(Integer id_campaign, Integer retries) {
		Long result = null;
		NamedQueryParameter param1 = new NamedQueryParameter("id_campaign", id_campaign);
		NamedQueryParameter param2 = new NamedQueryParameter("retries", retries);
		try {
			result = (Long) callDAO.findByNamedQueryNamedParameterReturnObject("Call.getProcesInValidFinish", param1,
					param2);
		} catch (EntityException e) {
			e.printStackTrace();
		}
		return result == null ? 0 : result.intValue();
	}

	public Integer getProcesGestion(Integer id_campaign, Integer retries) {
		Long result = null;
		NamedQueryParameter param1 = new NamedQueryParameter("id_campaign", id_campaign);
		NamedQueryParameter param2 = new NamedQueryParameter("retries", retries);
		try {
			result = (Long) callDAO.findByNamedQueryNamedParameterReturnObject("Call.getEnGestion", param1, param2);
		} catch (EntityException e) {
			e.printStackTrace();
		}
		return result == null ? 0 : result.intValue();
	}

	public Integer getProcesNoGestion(Integer id_campaign, Integer retries) {
		Long result = null;
		NamedQueryParameter param1 = new NamedQueryParameter("id_campaign", id_campaign);
		NamedQueryParameter param2 = new NamedQueryParameter("retries", retries);
		try {
			result = (Long) callDAO.findByNamedQueryNamedParameterReturnObject("Call.getNoGestionado", param1, param2);
		} catch (EntityException e) {
			e.printStackTrace();
		}
		return result == null ? 0 : result.intValue();
	}

	public Integer getTotalProcesGestion(Integer id_campaign, Integer retries) {
		Long result = null;
		NamedQueryParameter param1 = new NamedQueryParameter("id_campaign", id_campaign);
		NamedQueryParameter param2 = new NamedQueryParameter("retries", retries);
		try {
			result = (Long) callDAO.findByNamedQueryNamedParameterReturnObject("Call.getTotalProcesGestion", param1,
					param2);
		} catch (EntityException e) {
			e.printStackTrace();
		}
		return result == null ? 0 : result.intValue();
	}
}
